﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace UserInterfaceLayer.User
{
    public partial class RequestPrintPreview : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            lblDeletedItem.Visible = false;
            divDetails.Visible = false;
        }

        protected void Page_PreRender(object sender, EventArgs e)
        {
            string strRequestID = Request.QueryString["RequestID"];
            DataAccessLayer.linqDatabaseDataContext db = new DataAccessLayer.linqDatabaseDataContext();
            if (strRequestID != "add")
            {
                int RequestID;
                if (!int.TryParse(strRequestID, out RequestID))
                    Response.Redirect("~/");
                DataAccessLayer.Request mRequest = DataAccessLayer.Request.FindByRequestID_IncludeDeleted(db, RequestID);
                if (mRequest == null)
                    Response.Redirect("~/");
                divDetails.Visible = true;
                lvHistory.DataSource = BusinessLogicLayer.DataObject.Request.Convert(DataAccessLayer.Request.HistoryToListByRequestID(db, RequestID));
                lvHistory.DataBind();

                lvRequestRoom.DataSource = BusinessLogicLayer.DataObject.RequestRoom.Convert(DataAccessLayer.RequestRoom.ToListByRequestID(db, RequestID));
                lvRequestRoom.DataBind();
                lvRequestPerson.DataSource = BusinessLogicLayer.DataObject.RequestPerson.Convert(DataAccessLayer.RequestPerson.ToListByRequestID(db, RequestID));
                lvRequestPerson.DataBind();
                lvMessage.DataSource = BusinessLogicLayer.DataObject.Message.Convert(DataAccessLayer.Message.ToListByRequestID(db, RequestID));
                lvMessage.DataBind();
                lvCost.DataSource = BusinessLogicLayer.DataObject.Cost.Convert(DataAccessLayer.Cost.ToListByRequestID(db, RequestID));
                lvCost.DataBind();
                lvCar.DataSource = BusinessLogicLayer.DataObject.Car.Convert(DataAccessLayer.Car.ToListByRequestID(db, RequestID));
                lvCar.DataBind();
                lvSafekeeping.DataSource = BusinessLogicLayer.DataObject.Safekeeping.Convert(DataAccessLayer.Safekeeping.ToListByRequestID(db, RequestID));
                lvSafekeeping.DataBind();
            }
        }
    }
}